package com.zhou.simulation.service.impl;

import com.alibaba.fastjson.JSON;


import com.zhou.simulation.beans.MailInfoBean;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ProjectName: simulation
 * @Package: com.zhou.simulation.service.impl
 * @ClassName: MailService
 * @Author: zhoujingbo
 * @Description: 往中间件中写入数据
 * @Date: 2020/10/9 16:37
 * @Version: 1.0
 */
@Service
public class MailService {
    // 注入rabbitmqTemplate
    @Autowired
    RabbitTemplate rabbitTemplate;
    public void sendToRabbitMQ() {
        MailInfoBean mailInfoBean = new MailInfoBean();
        mailInfoBean.setSender("1377072049@qq.com");
        mailInfoBean.setRecipient("328827045@qq.com");
        mailInfoBean.setContent("测试邮件发给何宇");
        String jsonStr = JSON.toJSONString(mailInfoBean);
        rabbitTemplate.convertAndSend("message_send_exchange","mail.send",jsonStr);
    }
}
